package gotnames.dm;

/**
 * Return value from {@link FindOrCreate#go()}; use {@link #isNew()} to check if
 * the entity was created.
 */
public class PersistedEntityValue<X> {
	
	private final X ev;
	private final boolean isNew;
	
	private PersistedEntityValue(X ev, boolean isNew) {
		this.ev = ev;
		this.isNew = isNew;
	}
	
	static <X> PersistedEntityValue<X> found(X ev) { return new PersistedEntityValue<X>(ev, false); }
	
	static <X> PersistedEntityValue<X> created(X ev) { return new PersistedEntityValue<X>(ev, true); }
	
	/** The entity which was either found or created */
	public X getEntityValue() { return ev; }
	
	/** @return true if the entity was created */
	public boolean isNew() { return isNew; }

}
